﻿#include "Material.h"

namespace DYGraphics
{
	void Material::Setup()
	{
		mShader->use();
		int texId = GL_TEXTURE0;
		int texIdex = 0;
		for (auto it = propMap.begin(); it != propMap.end(); it++) {
			std::string key = it->first;
			MaterialProperty prop = it->second;
			switch (prop.type)
			{
			case MaterialProperty::Type::Int:
				mShader->SetInt(key, prop.data.intValue);
				break;
			case MaterialProperty::Type::Float:
				mShader->SetFloat(key, prop.data.floatValue);
				break;
			case MaterialProperty::Type::Float3:
				mShader->SetFloat3(key, prop.data.vec3Value);
				break;
			case MaterialProperty::Type::Float4:
				mShader->SetFloat4(key, prop.data.vec4Value);
				break;
			case MaterialProperty::Type::Matrix:
				mShader->SetMat4(key, prop.data.mat4);
				break;
			case MaterialProperty::Type::Texture:
				glActiveTexture(texId++);
				glBindTexture(GL_TEXTURE_2D, prop.data.texture->GetId());
				mShader->SetInt(key, texIdex++);
				break;
			default:
				break;
			}
		}
	}
}
